/*
 * Copyright (c) 2019.  drakelee.base All rights reserved.
 */

package com.base.components.database.dao.base;

import org.springframework.data.jpa.repository.support.JpaEntityInformation;
import org.springframework.data.jpa.repository.support.JpaEntityInformationSupport;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
import org.springframework.data.repository.NoRepositoryBean;

import javax.persistence.EntityManager;
import java.io.Serializable;

/**
 * @param <T> 实体类
 * @param <ID> 实体类ID
 *
 * @author DLee
 * @version V1.0
 * @Description JPA基础Dao实现
 * @date 2015年9月5日 下午3:32:55
 */
@NoRepositoryBean
public class GenericJpaDaoImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID>
  implements GenericJpaDao<T, ID> {

  private JpaEntityInformation<T, ?> entityInformation;

  public GenericJpaDaoImpl(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
    super(entityInformation, entityManager);
    this.entityInformation = entityInformation;
  }

  public GenericJpaDaoImpl(Class<T> domainClass, EntityManager em) {
    super(domainClass, em);
    this.entityInformation = JpaEntityInformationSupport.getEntityInformation(domainClass, em);
  }

  @Override
  public JpaEntityInformation<T, ?> getEntityInformation() {
    return entityInformation;
  }
}
